package com.antony.PlaneBattle0916;

import java.awt.Graphics;
import java.awt.Image;
import java.util.ArrayList;
import java.util.Random;

import javax.swing.ImageIcon;
import javax.swing.JFrame;

public class EnemyThread extends Thread {
	private int x, y = 0;
	private Graphics g;
	private JFrame jsf;
	private ArrayList<StoreThings> things;
	private Random rand = new Random();
	private boolean start = true;
	private boolean pause = true;

	public EnemyThread(Graphics g, JFrame jsf, ArrayList<StoreThings> things) {
		this.g = g;
		this.jsf = jsf;
		this.things = things;
	}
	
	public void setStart(boolean start){
		this.start = start;
	}
	
	public void setPause(boolean pause){
		this.pause =pause;
	}

	public void run() {
		while (start) {
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if (pause) {
				x = 100 + rand.nextInt(jsf.getWidth());
				Image image = new ImageIcon(this.getClass().getResource("EnemyPlane.png")).getImage();
				StoreThings st = new StoreThings(image, x, y, 80, 80, 10, g, "e_p", jsf, things);
				things.add(st);
				image = new ImageIcon(this.getClass().getResource("bullet1.png")).getImage();
				for (int i = 0; i < things.size(); i++) {
					StoreThings temp = things.get(i);
					if (temp.getType().equals("e_p")) {
						StoreThings Bullet = new StoreThings(image, temp.getX() + 28, temp.getY() + 40, 25, 25, 20, g,
								"e_b", jsf, things);
						things.add(Bullet);
					}
				}
			}
		}
	}
}
